package com.eascs.app.sharepush.dao;

import org.springframework.stereotype.Repository;

import com.eascs.admin.common.dao.BaseO2oDao;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.sharepush.entity.AppShareInfo;
import com.eascs.sharepush.vo.SharePushVo;

import jodd.util.StringUtil;

@Repository
public class SharePushDao extends BaseO2oDao {

	public AppShareInfo findAppShareInfoIsY(String system) {
		String sql = "SELECT * FROM app_share_info a WHERE a.system = ? AND a.is_new = 'Y'";
		return this.findEntity(sql, AppShareInfo.class, system);
	}

	public boolean updateAppShareInfo(AppShareInfo appShareInfo) {
		return this.updateById(appShareInfo) > 0 ? true : false;
	}

	public PageResult<Object[]> findShareInfoPage(SharePushVo sharePushVo) {
		SqlPageQuery<Object[]> pageQuery = new SqlPageQuery<>(Object[].class, 10, 0);
		StringBuffer querySql = new StringBuffer();
		querySql.append(" SELECT a.title,a.share_content,a.system,(CASE a.is_new WHEN 'Y' THEN '是' ELSE '否' END) as is_new,a.creator,a.creat_date FROM app_share_info a WHERE 1 = 1 ");
		if (!StringUtil.isBlank(sharePushVo.getSystem())) {
			querySql.append(" AND a.system = ? ");
			pageQuery.addParam(sharePushVo.getSystem());
		}
		querySql.append(" ORDER BY a.creat_date DESC ");
		pageQuery.setQuerySql(querySql.toString());
		return this.findDataWithPage(pageQuery);
	}
}
